<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.student.dao.StudentDao" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>删除结果</title>
    <style>
        .result {
            width: 400px;
            margin: 20px auto;
            padding: 20px;
            text-align: center;
        }
        .success {
            color: #4CAF50;
        }
        .error {
            color: #f44336;
        }
    </style>
</head>
<body>
    <div class="result">
        <%
        request.setCharacterEncoding("UTF-8");
        
        StringBuilder condition = new StringBuilder();
        ArrayList<String> conditions = new ArrayList<String>();
        
        String id = request.getParameter("id");
        if(id != null && !id.isEmpty()) {
            conditions.add("id = " + id);
        }
        
        String name = request.getParameter("name");
        if(name != null && !name.isEmpty()) {
            conditions.add("name = '" + name + "'");
        }
        
        String sex = request.getParameter("sex");
        if(sex != null && !sex.isEmpty()) {
            conditions.add("sex = '" + sex + "'");
        }
        
        String age = request.getParameter("age");
        if(age != null && !age.isEmpty()) {
            conditions.add("age = " + age);
        }
        
        String minWeight = request.getParameter("minWeight");
        String maxWeight = request.getParameter("maxWeight");
        if(minWeight != null && !minWeight.isEmpty() && maxWeight != null && !maxWeight.isEmpty()) {
            conditions.add("weight BETWEEN " + minWeight + " AND " + maxWeight);
        } else if(minWeight != null && !minWeight.isEmpty()) {
            conditions.add("weight >= " + minWeight);
        } else if(maxWeight != null && !maxWeight.isEmpty()) {
            conditions.add("weight <= " + maxWeight);
        }
        
        String minHeight = request.getParameter("minHeight");
        String maxHeight = request.getParameter("maxHeight");
        if(minHeight != null && !minHeight.isEmpty() && maxHeight != null && !maxHeight.isEmpty()) {
            conditions.add("height BETWEEN " + minHeight + " AND " + maxHeight);
        } else if(minHeight != null && !minHeight.isEmpty()) {
            conditions.add("height >= " + minHeight);
        } else if(maxHeight != null && !maxHeight.isEmpty()) {
            conditions.add("height <= " + maxHeight);
        }
        
        if(!conditions.isEmpty()) {
            condition.append(String.join(" AND ", conditions));
            
            StudentDao dao = new StudentDao();
            if(dao.deleteStudent(condition.toString())) {
                out.println("<h2 class='success'>删除成功！</h2>");
            } else {
                out.println("<h2 class='error'>删除失败！</h2>");
            }
        } else {
            out.println("<h2 class='error'>请至少指定一个删除条件！</h2>");
        }
        %>
    </div>
</body>
</html> 